/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2023-10-24
 * Time: 10:25
 */
public class NumberSearch {
    public static void main(String[] args) {
        findNumbers();
    }

    public static void findNumbers() {
        for (int i = 10000; i <= 49999; i++) {
            int product = i * 2;
            if (isDistinctDigits(i) && isDistinctDigits(product)) {
                String digits = String.valueOf(i) + String.valueOf(product);
                if (isDistinctDigits(digits)) {
                    System.out.println("满足条件的5位数：" + i);
                    System.out.println("满足条件的4位数：" + product);
                    break;
                }
            }
        }
    }

    public static boolean isDistinctDigits(int number) {
        String digits = String.valueOf(number);
        return isDistinctDigits(digits);
    }

    public static boolean isDistinctDigits(String digits) {
        for (int i = 0; i < digits.length(); i++) {
            for (int j = i + 1; j < digits.length(); j++) {
                if (digits.charAt(i) == digits.charAt(j)) {
                    return false;
                }
            }
        }
        return true;
    }
}
